package com.taptech.doufu.umeng.push;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.umeng.message.UTrack;
import com.umeng.message.entity.UMessage;

import org.android.agoo.common.AgooConstants;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 接收自定义消息的点击事件
 */
public class UmengNotificationClickReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String body = intent.getStringExtra(AgooConstants.MESSAGE_BODY);
        if (!TextUtils.isEmpty(body)) {
            try {
                //上报点击行为
                JSONObject jsonObject = new JSONObject(body);
                UMessage uMessage = new UMessage(jsonObject);
                UTrack.getInstance(context).trackMsgClick(uMessage);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        PushManager.getInstance().handlerMsg(intent);
    }
}
